package l_network;
// ================================================
// url class로 관련 정보 얻기
// make : pwg
// date : 2003
// note : protocol, host, port, file, ref 확인
// ================================================

import java.awt.*;
import java.awt.event.*;
import java.net.*;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JButton;

public class UrlEx extends JFrame 
				implements ActionListener{
	myWindowAdapter myW;

	URL       url;
	private JTextField textDomain;
	private JScrollPane scrollPane;
	private JTextArea textResult;
	private JButton btnNewButton;

	public UrlEx(){
		getContentPane().setLayout(null);

		myW = new myWindowAdapter();
		addWindowListener(myW);
		getContentPane().add(getTextDomain());
		getContentPane().add(getScrollPane());
		getContentPane().add(getBtnNewButton());


	}

	public static void main(String args[]){
		UrlEx f= new UrlEx();
		f.setSize(350,300);
		f.setVisible(true);
	}

	public void actionPerformed(ActionEvent e){
		try	{
			url=new URL( textDomain.getText() );

			textResult.append("Protocol = " + url.getProtocol() + "\n" );
			textResult.append("Host     = " + url.getHost() + "\n" );
			textResult.append("Port     = " + url.getPort() + "\n" );
			textResult.append("File     = " + url.getFile() + "\n" );
			textResult.append("Ref      = " + url.getRef() + "\n" );
			textResult.append("-----------------------------------\n");
			
		}
		catch (Exception ex)	{
			textResult.append("error \n");
		}
	}

	class myWindowAdapter extends WindowAdapter	{
		public void windowClosing(WindowEvent ee)	{
			System.exit(0);
		}
	}
	private JTextField getTextDomain() {
		if (textDomain == null) {
			textDomain = new JTextField();
			textDomain.setText("http://www.jobtc.kr");
			textDomain.setToolTipText("http://www.jobtc.kr 유형으로");
			textDomain.setBounds(30, 30, 196, 21);
			textDomain.setColumns(10);
		}
		return textDomain;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(30, 61, 305, 176);
			scrollPane.setViewportView(getTextResult());
		}
		return scrollPane;
	}
	private JTextArea getTextResult() {
		if (textResult == null) {
			textResult = new JTextArea();
		}
		return textResult;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("RUN");
			btnNewButton.setBounds(238, 29, 97, 23);
		}
		return btnNewButton;
	}
}
